﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using SmartWarehouse.Common;
using SmartWarehouse.ORM.Entity;
using SmartWarehouse.BussinessLogic.Basis;

public partial class UserManagement : SwBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            InitRole();
            InitUserStatus();
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        SwUser user = new SwUser();
        user.Name = this.txtName.Text.Trim();
        user.Password = "123"; //Fixed to 123, need change when login first
        user.Phone = this.txtPhone.Text.Trim();
        user.Mail = this.txtMail.Text.Trim();
        user.Role = this.drpRole.SelectedValue;
        user.Status = this.drpUserStatus.SelectedValue;
        user.Address = this.txtAddress.Text.Trim();


        UserFacade userFacade = new UserFacade();
        SwMessage message =  userFacade.AddUser(user);
        this.ShowMessage(message);
    }
    protected void InitRole()
    {
        this.drpRole.Items.Add(new ListItem("管理员", "Admin"));
        this.drpRole.Items.Add(new ListItem("用户", "User"));
        this.drpRole.Items.Add(new ListItem("专家", "Expert"));
    }
    protected void InitUserStatus()
    {
        this.drpUserStatus.Items.Add(new ListItem("激活", "A"));
        this.drpUserStatus.Items.Add(new ListItem("未激活", "U"));
        this.drpUserStatus.Items.Add(new ListItem("锁定", "L"));
        this.drpUserStatus.Items.Add(new ListItem("删除", "D"));
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        this.txtName.Text = string.Empty;
        this.txtPhone.Text = string.Empty;
        this.txtMail.Text = string.Empty;
        this.txtAddress.Text = string.Empty;
    }
}
